package com.msb.result;

import lombok.Data;

import java.io.Serializable;

/**
 * @ClassName: Result
 * @Author: zw
 * @Description: 出百万拳，行万里路；
 * @Create 2024/8/4-09:00
 * @Version 1.0
 */
@Data
public class Result <T> implements Serializable {
    private Integer code; //编码：1成功，0和其它数字为失败
    private String msg; //错误信息
    private T data; //数据

    public static <T> Result<T> success() {
        Result<T> result = new Result<T>();
        result.code = 1;
        return result;
    }

    public static <T> Result<T> success(T object) {
        Result<T> result = new Result<T>();
        result.data = object;
        result.code = 1;
        return result;
    }

    public static <T> Result<T> error(String msg) {
        Result result = new Result();
        result.msg = msg;
        result.code = 0;
        return result;
    }

    public static <T> Result<T> ok() {
        Result result = new Result();
        result.msg = "ok";
        result.code = 200;
        return result;
    }

    public static <T> Result<T> custom(Integer code,String msg, String data) {
        Result result = new Result();
        result.msg = msg;
        result.code = code;
        result.data = data;
        return result;
    }
}
